package com.ruoyi.web.controller.walmart;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.AuthBrand;
import com.ruoyi.common.core.domain.Platform;
import com.ruoyi.common.core.domain.SiteForm;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.walmart.domain.auth.ShopAuth;
import com.ruoyi.walmart.service.auth.PlatformService;
import com.ruoyi.walmart.service.auth.ShopAuthService;
import com.ruoyi.walmart.service.auth.SiteFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/auth")
public class ShopAuthController extends BaseController {
    @Autowired
    ShopAuthService shopAuthService;
    @Autowired
    PlatformService platformService;

    @Autowired
    SiteFormService siteFormService;


    /** 判断店铺授权 */
    @GetMapping("/shopAuth")
    public AjaxResult getShopAuth(ShopAuth shopAuth){
        return success(shopAuthService.authFlay(shopAuth));
    }

    /** 查询所有店铺授权记录 */
    @GetMapping("/list")
    public AjaxResult list(){
        List<ShopAuth> shopAuths = shopAuthService.selectAllList(null);
        return success(shopAuths);
    }

    /** 删除店铺授权记录 */
    @DeleteMapping("/{authId}")
    public AjaxResult remove(@PathVariable Long authId){
        return toAjax(shopAuthService.deleteByAuthIdInt(authId));
    }

    @GetMapping("/{authId}")
    public AjaxResult getInfo(@PathVariable Long authId){
        return success(shopAuthService.selectByAuthId(authId));
    }

    /** 重新授权店铺 */
    @PutMapping
    public AjaxResult edit(@RequestBody ShopAuth shopAuth){
        return toAjax(shopAuthService.updateShopAuth(shopAuth));
    }

    /** 查询店铺分类 */
    @GetMapping("/platFormTree")
    public AjaxResult platFormTree(Platform platform){
        return success(platformService.selectPlatformTreeList(platform));
    }

    /** 查询站点分类 */
    @GetMapping("/siteFormTree")
    public AjaxResult siteFormTree(SiteForm siteForm){
        return success(siteFormService.selectSiteFormTreeList(siteForm));
    }

    /**
     * 查询品牌
     * @param authBrand
     * @return
     */
    @GetMapping("/selectAuthBrand")
    public AjaxResult getSelectAuthBrand(AuthBrand authBrand){
        return success(shopAuthService.selectAuthBrand(authBrand));
    }


    /**
     * 添加品牌
     * @param authBrand
     * @return
     */
    @PostMapping("/authBrandInsert")
    public AjaxResult getAuthBrandInsert(@RequestBody AuthBrand authBrand){
        return success(shopAuthService.authBrandInsert(authBrand));
    }

    /**
     * 品牌详情页
     * @param authBrandId
     * @return
     */
    @GetMapping("/selectByAuthBrandId/{authBrandId}")
    public AjaxResult getSelectByAuthBrandId(@PathVariable Long authBrandId){
        return success(shopAuthService.selectByAuthBrandId(authBrandId));
    }

    /**
     * 修改品牌
     * @param authBrand
     * @return
     */
    @PutMapping("/updateAuthBrand")
    public AjaxResult getUpdateAuthBrand(@RequestBody AuthBrand authBrand){

        return toAjax(shopAuthService.updateAuthBrand(authBrand));
    }

    /**
     * 删除品牌
     * @param authBrandId
     * @return
     */
    @DeleteMapping("/updateByAuthBrandId/{authBrandId}")
    public AjaxResult getUpdateByAuthBrandId(@PathVariable Long authBrandId){
        return toAjax(shopAuthService.updateByAuthBrandId(authBrandId));
    }

    /**
     * 递归品牌
     * @param authBrand
     * @return
     */
    @GetMapping("/authBrandTree")
    public AjaxResult getAuthBrandTree(AuthBrand authBrand){
        return success(shopAuthService.selectAuthBrandTreeList(authBrand));
    }
}
